package com.godyao.service;

import com.godyao.dao.UserDao;
import com.godyao.framework.beans.factory.*;
import com.godyao.framework.beans.factory.support.DefaultListableBeanFactory;
import com.godyao.framework.context.ApplicationContext;
import com.godyao.framework.context.support.ClassPathXmlApplicationContext;

public class UserService2 implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, ApplicationContextAware {

    private UserDao userDao;

    private Integer count;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    // 测试BeanFactoryPostProcessor
    private String location;

    private String company;

    public UserService2(Integer count) {
        this.count = count;
    }


    public UserService2() {

    }

    public String getUser(int id) {
        return userDao.getUserById(id);
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        System.out.println("执行ApplicationContextAware的setApplicationContext方法得到ApplicationContext=" + applicationContext);
    }

    @Override
    public void setBeanClassLoader(ClassLoader cl) {
        System.out.println("执行BeanClassLoaderAware的setBeanClassLoader方法得到当前bean的ClassLoader=" + cl);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        System.out.println("执行BeanFactoryAware的setBeanFactory方法获取到spring容器中的BeanFactory=" + beanFactory);
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("执行BeanNameAware的setBeanName方法获取到当前bean在spring容器中注册的名字=" + beanName);
    }
}
